import java.util.Arrays;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution80 {

    public static void main(String args[]) {
        Solution80 s = new Solution80();
        System.out.println(s.removeDuplicates(new int[]{1, 1, 1, 2, 2, 2, 3, 4, 4, 4}));
    }

    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int ret = 1;
        int pre = nums[0];
        int count = 1;
        int idx = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == pre) {
                count++;
            } else {
                count = 1;
            }
            if (count <= 2) {
                ret++;
                nums[idx++] = nums[i];
            }
            pre = nums[i];

        }
        System.out.println(Arrays.toString(nums));
        return ret;
    }

}
